<template>
	<view class="sideBox">
		<view class="content">
			<view class="uni-column">         
				<view><text>账号：</text><input @blur="change1" class="uni-input" focus placeholder="请输入账号" /></view>
				<view><text>密码：</text><input @blur="change2" class="uni-input" password type="text" placeholder="请输入密码" /></view>
				<!-- <view><text>code码：</text><input @blur="change3" class="uni-input" placeholder="请输入code账号" /></view> -->
				<button type="default" @click="loginIn">登录</button>
			</view>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				password:'',
				phone:'',
				code:''
			}
		},
		onLoad() {

		},
		methods: {
			change1(e){
				console.log(e.detail.value);
				this.phone = e.detail.value;
			},
			change2(e){
				this.password = e.detail.value;
			},
			// change3(e){
			// 	this.code = e.detail.value;
			// },
			loginIn(){
				uni.login({
					provider:'weixin',
					success:res=>{
						if(res.code){
							this.code = res.code;
							// uni.request({
							// 	url:'https://api.weixin.qq.com/sns/jscode2session',
							// 	data:{
							// 		appid:'wxfdf5cabd1245dbd8',
							// 		secret:'c5a4531c541648abb17147da86976701',
							// 		js_code:this.code,
							// 		grant_type: 'authorization_code'
							// 	}
							// }).then(res => {
							// 	console.log(res);
							// })
							// console.log(res.code);
							uni.request({
								url:'http://172.17.26.211:3313/user/onlogin',
								data:{
									code:this.code,
									password:this.password,
									phone:this.phone
									// password:'222222',
									// phone:'18622222222'
								},
								success(res){
									console.log(res.data.data.id);
									if(res.data.data.id){
										uni.setStorageSync('user', res.data.data);
										uni.reLaunch({
											url:'../mine/mine'
										})
									}
									
								}
							})
						}else{
							console.log('登录失败' + res.errMsg)
						}
					}
				})
			}
		}
	}
</script>

<style lang="less" scoped>
.sideBox {
	width: 750rpx;
	.content {
		width:680rpx;
		margin: 0 auto;
		.uni-column {
			margin-top: 50rpx;
			width: 500rpx;
			background: #eee;
			box-shadow: 0 0 12rpx 2rpx #00000020;
			display: flex;
			flex-direction: column;
			// justify-content: ;
			>view {
				display: flex;
				height: 70rpx;
				align-items: center;
				padding-left: 30rpx;
				
			}
		}
	}
}

	
</style>
